package com.codermn.demo4;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author jxau_scf
 * @date 2021/6/2 - 17:26
 */
public class Member extends User {
    public Member() {
    }
    public Member(String name, int money){
        super(name, money);
    }

    public void receive(ArrayList<Integer> list){
        int index = new Random().nextInt(list.size());
        int getMoney = list.remove(index);
        int money = super.getMoney();
        super.setMoney(money+getMoney);

    }
    public ArrayList<Integer> send(int totalMoney, int count){
        ArrayList<Integer> list = new ArrayList<>();
        int leftMoney = super.getMoney();
        if (totalMoney > leftMoney){
            System.out.println("余额不足！");
            return list;
        }else {
            super.setMoney(leftMoney - totalMoney);
            int avg = totalMoney / count;
            int mod = totalMoney % count;

            for (int i = 0;i<count - 1;i++){
                list.add(avg);
            }
            int last = avg + mod;
            list.add(last);
            return list;
        }
    }

}
